package com.spark.incoicings.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spark.incoicings.dao.OrderDetailMapper;
import com.spark.incoicings.dao.ReturnDetailMapper;
import com.spark.incoicings.dao.SalesOrderMapper;
import com.spark.incoicings.dao.SalesReturnMapper;
import com.spark.incoicings.service.ReturnDetailService;
import com.spark.invoicings.entity.OrderDetail;
import com.spark.invoicings.entity.ReturnDetail;
import com.spark.invoicings.entity.SalesOrder;
import com.spark.invoicings.entity.SalesReturn;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class ReturnDetailServiceImpl extends ServiceImpl<ReturnDetailMapper, ReturnDetail>
                                     implements ReturnDetailService {

    @Resource
    private ReturnDetailMapper returnDetailMapper;
    @Resource
    private SalesReturnMapper returnMapper;
    @Resource
    private OrderDetailMapper orderDetailMapper;
    @Resource
    private SalesOrderMapper salesOrderMapper;
    /**
     * 查询所有退货明细
     * @param map
     * @return
     */
    @Override
    public List<ReturnDetail> selectReturnDetailAll(Map<String, Object> map) {
        List<ReturnDetail> returnDetails = returnDetailMapper.selectReturnDetailAll(map);
        returnDetails.forEach(returnDetail -> {
            SalesReturn salesReturn = returnMapper.selectById(returnDetail.getReturnOrderId());
            returnDetail.setSalesReturn(salesReturn);
            SalesOrder salesOrder = salesOrderMapper.selectById(salesReturn.getOrderId());
            salesReturn.setSalesOrder(salesOrder);
            OrderDetail orderDetail = orderDetailMapper.selectById(returnDetail.getOrderDetailId());
            returnDetail.setOrderDetail(orderDetail);
        });
        log.info("returnDetails{}",returnDetails);
        return returnDetails;
    }
}
